package com.controller;

import com.resp.BaseResponseEntity;
import com.service.ICartService;
import com.service.impl.CartServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 删除购物内的商品
 */
@WebServlet("/DeleteIphone")
public class DeleIphoneController extends HttpServlet {
    ICartService service=new CartServiceimpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        String parameter = req.getParameter("pid");
        int pid = Integer.parseInt(parameter);

        Integer integer = service.DeleteCart(name, pid);

        BaseResponseEntity entity=null;
        if(integer!=null){
            entity=new BaseResponseEntity(200,"删除成功",integer);
        }else {
            entity=BaseResponseEntity.error();
        }



    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req, resp);
    }
}
